package com.TeacherInfoServer.controller;

import com.TeacherInfoServer.common.Result;
import com.TeacherInfoServer.pojo.DTO.AddTypeInfoDTO;
import com.TeacherInfoServer.pojo.entity.TypeInfo;
import com.TeacherInfoServer.common.service.TypeInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/s1/typeInfo")
@Tag(name = "类型信息控制器",description = "用于类型信息的控制")
public class TypeInfoController {

    @Autowired
    public TypeInfoService typeInfoService;

    @Operation(summary = "获取类型信息列表",description = "分页获取类型信息列表")
    @GetMapping("/getList")
    public Result<Map<String,Object>> getAllList(@RequestParam("pages") @Parameter(description = "当前页数") Integer pages,
                                                 @RequestParam("size") @Parameter(description = "当前页数显示信息的数量") Integer size){
        return Result.success("获取类型信息列表成功",typeInfoService.getList(pages,size));
    }
    @Operation(summary = "分页获取相对应类型信息列表",description = "分页获取相对应类型信息列表")
    @GetMapping("/getListByName")
    public Result<Map<String,Object>> getAllListByName(@RequestParam("pages") @Parameter(description = "当前页数") Integer pages,
                                                 @RequestParam("size") @Parameter(description = "当前页数显示信息的数量") Integer size,
                                                       @RequestParam("name") @Parameter(description = "类型名") String name){
        return Result.success("获取相对应类型信息列表成功",typeInfoService.getListByName(pages,size,name));
    }

    @Operation(summary = "根据类型名获取相对应类型取值信息列表",description = "获取相对应类型信息取值列表")
    @GetMapping("/getValueByName")
    public Result<?> getValueByName(@RequestParam("name")@Parameter(description = "类型名") String name){
        return Result.success("获取相对应取值成功",typeInfoService.getOneNameList(name));
    }

    @Operation(summary = "添加一个TypeInfo",description = "添加一个TypeInfo")
    @PostMapping("/addOne")
    public Result<String> addOne(@RequestBody AddTypeInfoDTO addTypeInfoDTO){
        typeInfoService.addOne(addTypeInfoDTO);
        return Result.success(typeInfoService.addOne(addTypeInfoDTO));
    }

    @Operation(summary = "根据id修改",description = "根据id修改")
    @PostMapping("/updateById")
    public Result<String> addOne(@RequestBody TypeInfo typeInfo){
        typeInfoService.updateById(typeInfo);
        return Result.success("修改成功");
    }

    @Operation(summary = "根据id删除",description = "根据id删除对应的类型")
    @DeleteMapping("/deleteByIds")
    public Result<String> deleteByIds(@RequestBody List<Integer> list){
        typeInfoService.removeBatchByIds(list);
        return Result.success("删除成功");
    }

    @Operation(summary = "根据类别获取所有的类型",description = "根据类别获取所有的类型")
    @GetMapping("/getByCategory")
    public Result<?> getByCategory(@RequestParam("category")@Parameter(description = "类别") String category){
        return Result.success("获取相对应类别成功",typeInfoService.getByCategoryList(category));
    }
}
